package com.dongwu.config;

import java.util.Map;


import com.dongwu.common.constants.DongwuManagerConstant;
import com.dongwu.common.utils.Encodes;
import com.dongwu.common.utils.HttpClientUtils;
import com.gexin.fastjson.JSON;

/**
 * 调用短链系统
 * @author xyj
 *
 */
public class Slink {
	/**
	 *  获取短链
	 * @param url
	 * @return String slinkUrl
	 */
	public	static String getSlink(String url){
		String urlEncoder = Encodes.urlEncode(url);
		// 调用短链系统
		try {
			String httpResponse = HttpClientUtils.HttpGetResStr(DongwuManagerConstant.SLINKSERVERURL + "?userId="
					+ DongwuManagerConstant.SLINKSERVERUSERID + "&originalUrl=" + urlEncoder);
			Map<String, Object> mapTypes = JSON.parseObject(httpResponse);
			if (Integer.parseInt(mapTypes.get("code").toString()) == 0) {
				return mapTypes.get("response").toString();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return null;
	}
}
